package cn.fl.mcr.service.impl;

import java.util.List;

import cn.lionbridgecapital.loan.model.base.Pager;
import cn.lionbridgecapital.loan.model.condition.McrCstCreditBlQC;
import cn.lionbridgecapital.loan.model.dto.McrCstCreditBlDTO;
import cn.lionbridgecapital.loan.service.api.IMcrCstCreditBlApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mcr.service.IMcrCstCreditBlService;
import cn.fl.mcr.transform.McrCstCreditBlVOTransform;
import cn.fl.mcr.vo.McrCstCreditBlVO;

/**
 * @Description: 客户小贷授信黑名单 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class McrCstCreditBlServiceImpl implements IMcrCstCreditBlService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IMcrCstCreditBlService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IMcrCstCreditBlApiService publicMcrCstCreditBlApiService;

	@Override
	public McrCstCreditBlVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//TODO 业务逻辑
		McrCstCreditBlDTO dto = publicMcrCstCreditBlApiService.selectMcrCstCreditBlDTOById(id);
		return McrCstCreditBlVOTransform.toVO(dto);
	}

	@Override
	public Long add(McrCstCreditBlVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.publicMcrCstCreditBlApiService.addMcrCstCreditBl(McrCstCreditBlVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.publicMcrCstCreditBlApiService.removeById(id);
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(McrCstCreditBlVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.mcrCstCreditBlApiService.modify(McrCstCreditBlVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return this.publicMcrCstCreditBlApiService.modifyMcrCstCreditBlDTO(McrCstCreditBlVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		Pager pager =this.publicMcrCstCreditBlApiService.searchMcrCstCreditBlListPage(page);
		List<McrCstCreditBlDTO> dtoList = (List<McrCstCreditBlDTO>) pager.getResultList();
		pager.setResultList(McrCstCreditBlVOTransform.toVOList(dtoList));
		return pager;
	}

	@Override
	public boolean cancel(McrCstCreditBlVO entity) throws BaseException {
		if(null == entity){
			BaseLogUtils.info(logger, "cancel", "作废对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return publicMcrCstCreditBlApiService.cancelMcrCstCreditBlDTO(entity.getId());
	}

	@Override
	public List<McrCstCreditBlVO> searchList(McrCstCreditBlQC qc)throws BaseException {
		if(null == qc){
			BaseLogUtils.info(logger, "cancel", "作废对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			qc = new McrCstCreditBlQC();
		}
		 List<McrCstCreditBlVO> list =McrCstCreditBlVOTransform.toVOList(publicMcrCstCreditBlApiService.searchMcrCstCreditBlDTOList(qc));
		 return list;
	}

	
	@Override
	public boolean queryIsBlackByLnkCompNm(String lnkCompNm)
			throws BaseException {
		 boolean flag = publicMcrCstCreditBlApiService.queryIsBlackByLnkCompNm(lnkCompNm);
		 return flag;
	}
	
	
}
